package com.city.java.announcements.pojo.entity;

import lombok.Data;
import java.time.LocalDateTime;

/**
 * 公告实体类
 */
@Data
public class Announcements {
    private Long announcementId;
    private String title;
    private String content;
    private AnnouncementType type; // community/legal
    private AnnouncementStatus status; // draft/finalized
    private String imageUrl;
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;

    /**
     * 公告类型枚举 - 对应数据库 ENUM('community', 'legal')
     */
    public enum AnnouncementType {
        community("community"),
        legal("legal");

        private final String value;

        AnnouncementType(String value) {
            this.value = value;
        }

        public String getValue() {
            return value;
        }

        public static AnnouncementType fromValue(String value) {
            for (AnnouncementType type : values()) {
                if (type.value.equalsIgnoreCase(value)) {
                    return type;
                }
            }
            throw new IllegalArgumentException("Invalid announcement type: " + value);
        }

        @Override
        public String toString() {
            return this.value;
        }
    }

    /**
     * 公告状态枚举 - 对应数据库 ENUM('draft', 'finalized')
     */
    public enum AnnouncementStatus {
        draft("draft"),
        finalized("finalized");

        private final String value;

        AnnouncementStatus(String value) {
            this.value = value;
        }

        public String getValue() {
            return value;
        }

        public static AnnouncementStatus fromValue(String value) {
            for (AnnouncementStatus status : values()) {
                if (status.value.equalsIgnoreCase(value)) {
                    return status;
                }
            }
            throw new IllegalArgumentException("Invalid announcement status: " + value);
        }

        @Override
        public String toString() {
            return this.value;
        }
    }
}
